#pragma once
#include <vector>
#include <memory>
#include <lambda/lambda.hpp>
#include <lambda/bind.hpp>
#include <lambda/construct.hpp>
using namespace std;
using namespace boost::lambda;
namespace Core
{
	namespace Util
	{
		template<class T,class Pr>
		class Heap
		{
			vector<T*> holder;
			Pr& less;
		public:
			Heap(Pr& Less):less(Less)
			{
				//holder.push_back(oneNode);
				//::make_heap(holder.begin(),holder.end(),less);
			}
			void push(T* oneNode)//return a pointer to track the just added element
			{
				holder.push_back(oneNode);
				holder.back();
				::push_heap(holder.begin(),holder.end(),less);

			}
			bool pop(T*& oneNode)
			{
				if(holder.empty()) return false;
				::pop_heap(holder.begin(),holder.end(),less);
				oneNode=holder.back();
				holder.pop_back();
				return true;
			}
		public:
			~Heap(void)
			{
				for_each(holder.begin(),holder.end(),bind(delete_ptr(),_1));
			}
		};
	}
}